﻿using Microsoft.Practices.Prism.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using WebServerConnectorDll;

namespace FridgeManagerApp
{
    [DataContract]
    public class WPersonnelGroupPermission : NotificationObject
    {
        public int nexusUID;
        private int personnelGroupUID;
        private String permissionUID;

        [DataMember(Order = 0)]
        public int NexusUID
        {
            get
            {
                return nexusUID;
            }
            set
            {
                nexusUID = value;
                RaisePropertyChanged("NexusUID");
            }
        }

        [DataMember(Order = 1)]
        public int PersonnelGroupUID
        {
            get
            {
                return personnelGroupUID;
            }
            set
            {
                personnelGroupUID = value;
                RaisePropertyChanged("PersonnelGroupUID");
            }
        }

        [DataMember(Order = 2)]
        public String PermissionUID
        {
            get
            {
                return permissionUID;
            }
            set
            {
                permissionUID = value;
                RaisePropertyChanged("PermissionUID");
            }
        }

        public WPersonnelGroupPermission()
        {
            NexusUID = -1;
            PersonnelGroupUID = -1;
            PermissionUID = "";
        }

        public static List<WPersonnelGroupPermission> GetAll()
        {
            HttpResponse res = FridgeConnector.PostMessage(EStudy.PersonnelGroupPermission, EMethod.SelectAll, "");
            return JSON.parse<List<WPersonnelGroupPermission>>(res.Data1);
        }

        public static List<WPersonnelGroupPermission> Select(String pPersonnelGroupName)
        {
            int personnelGroupUId = WPersonnelGroup.GetPersonnelGroupUID(pPersonnelGroupName);
            WPersonnelGroupPermission item = new WPersonnelGroupPermission();
            item.PersonnelGroupUID = personnelGroupUId;
            List<WPersonnelGroupPermission> list = new List<WPersonnelGroupPermission>();
            list.Add(item);
            String postData = JSON.stringify(list);
            HttpResponse res = FridgeConnector.PostMessage(EStudy.PersonnelGroupPermission, EMethod.Select, postData);
            return JSON.parse<List<WPersonnelGroupPermission>>(res.Data1);
        }

        public static HttpResponse Insert(List<WPersonnelGroupPermission> pList)
        {
            String postData = JSON.stringify(pList);
            return FridgeConnector.PostMessage(EStudy.PersonnelGroupPermission, EMethod.Insert, postData);
        }

        public static HttpResponse Update(List<WPersonnelGroupPermission> pList)
        {
            String postData = JSON.stringify(pList);
            return FridgeConnector.PostMessage(EStudy.PersonnelGroupPermission, EMethod.Update, postData);
        }

        public static HttpResponse Delete(int pPersonnelGroupUID)
        {
            List<WPersonnelGroupPermission> list = new List<WPersonnelGroupPermission>();
            WPersonnelGroupPermission wPersonnelGroupPermission = new WPersonnelGroupPermission();
            wPersonnelGroupPermission.PersonnelGroupUID = pPersonnelGroupUID;
            list.Add(wPersonnelGroupPermission);
            String postData = JSON.stringify(list);
            return FridgeConnector.PostMessage(EStudy.PersonnelGroupPermission, EMethod.Delete, postData);
        }
    }
}
